package com.jinmdz.fmis.mapper.mapper;

import com.jinmdz.fmis.mapper.entity.DocumentFileEntity;
import com.jinmdz.fmis.mapper.mapper.provider.DocumentFileProvider;
import org.apache.ibatis.annotations.*;

import java.util.ArrayList;

/**
 * 公用图片及文件表Mapper
 *
 * @author generator
 * @date 2020-03-12 17:08
 */
public interface DocumentFileMapper {

    /**
     * 增加DocumentFile
     *
     * @param entity 数据实体
     * @return
     * @author generator
     * @date 2020-03-12 17:08
     */
    @InsertProvider(type = DocumentFileProvider.class, method = "insertDocumentFile")
    @Options(useGeneratedKeys = true, keyProperty = "entity.id", keyColumn = "id")
    void insertDocumentFile(@Param("entity") DocumentFileEntity entity);

    /**
     * 删除DocumentFile
     *
     * @param id             主键
     * @param modifiedUserId 修改用户外键
     * @param version        版本号
     * @return
     * @author generator
     * @date 2020-03-12 17:08
     */
    @Update(" update document_file set deleted = 1,modified_user_id = #{modifiedUserId},version = unix_timestamp(now()) where id = #{id} and version = #{version} and unmodified = 0 and deleted = 0 ")
    void deletedForDocumentFile(@Param("id") Integer id, @Param("modifiedUserId") Integer modifiedUserId, @Param("version") Long version);

    /**
     * 修改DocumentFile
     *
     * @param entity 数据实体
     * @return
     * @author generator
     * @date 2020-03-12 17:08
     */
    @UpdateProvider(type = DocumentFileProvider.class, method = "updateDocumentFile")
    void updateDocumentFile(@Param("entity") DocumentFileEntity entity);

    /**
     * 查询DocumentFile实体
     *
     * @param id 主键
     * @return DocumentFileEntity
     * @author generator
     * @date 2020-03-12 17:08
     */
    @Select(" select id,deleted,table_name,table_id,business_code,document_type_code,file_name,file_path,file_length,file_extension,thumb_path,file_describe,file_code,random_code,remark,funeral_parlour_code,create_user_id,gmt_create,unmodified,modified_user_id,gmt_modified,version from document_file where id = #{id} and deleted = 0 limit 1 ")
    DocumentFileEntity getDocumentFileById(@Param("id") Integer id);


    /**
     * 查询DocumentFile列表
     *
     * @param entity 数据实体
     * @return DocumentFileEntity
     * @author generator
     * @date 2020-03-12 17:08
     */
    @SelectProvider(type = DocumentFileProvider.class, method = "listDocumentFile")
    ArrayList<DocumentFileEntity> listDocumentFile(@Param("entity") DocumentFileEntity entity);
}